package com.ruitu.router_module.bean;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.beanu.arad.base.my_base.Config;
import com.beanu.arad.base.my_base.base_list.ListBaseAdapter;
import com.beanu.arad.base.my_base.base_list.SuperViewHolder;
import com.beanu.arad.utils.ScreenUtils;
import com.beanu.arad.utils.SizeUtils;
import com.beanu.arad.utils.UIUtils;
import com.ruitu.router_module.R;
import com.ruitu.router_module.bean.product.ProHome;
import com.ruitu.router_module.utils.GlideUtil;

/**
 * Created by Administrator on 2018/3/27.
 * 首页底部商品列表adapter
 */
public class DataAdapter extends ListBaseAdapter<ProHome> {
    public DataAdapter(Context context) {
        super(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.app_item_home_model_pro;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        TextView tv_name = holder.getView(R.id.tv_name);
        TextView tv_price = holder.getView(R.id.tv_price);
        TextView tv_old_price = holder.getView(R.id.tv_old_price);
        TextView tv_num = holder.getView(R.id.tv_num);
        ImageView icon = holder.getView(R.id.icon);

        int width = ScreenUtils.getScreenWidth();
        int itemWidth = (width - (SizeUtils.dp2px(40))) / 2;
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) icon.getLayoutParams();
        params.width = itemWidth;
        params.height = itemWidth;
        icon.setLayoutParams(params);

        ProHome pro = mDataList.get(position);
        tv_name.setText(pro.getGoodsName());
        tv_price.setText("￥" + pro.getPrice());
        tv_old_price.setText("￥" + pro.getOriginalPrice());
        UIUtils.setDelLine(tv_old_price);
        tv_num.setText(pro.getCount() + "评论");
        GlideUtil.loadImg(Config.BASE_URL + pro.getImageUrl(), icon);

        TextView tv_sale_num = holder.getView(R.id.tv_sale_num);//销量
        if (null != tv_sale_num) {
            tv_sale_num.setText("销量" + (pro.getGoodVolume() > 999 ? 999 + "+" : pro.getGoodVolume() + ""));
        }

        //下面是设置标签的,只适用于部分页面
        TextView tag_zidingyi = holder.getView(R.id.tag_zidingyi);//自定义
        TextView tag_pintuan = holder.getView(R.id.tag_pintuan);//拼团
        TextView tag_qujianjia = holder.getView(R.id.tag_qujianjia);//区间价
        TextView tag_yuding = holder.getView(R.id.tag_yuding);//预订
        TextView tag_yushou = holder.getView(R.id.tag_yushou);//预售

        try {
            if (!TextUtils.isEmpty(pro.getGoodTagName())) {//是否有自定义标签
                tag_zidingyi.setVisibility(View.VISIBLE);
                tag_zidingyi.setText(pro.getGoodTagName());//设置自定义标签名称
            } else {
                tag_zidingyi.setVisibility(View.GONE);
            }
        } catch (Exception e) {
        }
        try {
            if (TextUtils.equals("1", pro.getShoppingGroupStatus())) {//是否团购 0 否 1 是
                tag_pintuan.setVisibility(View.VISIBLE);
            } else {
                tag_pintuan.setVisibility(View.GONE);
            }
        } catch (Exception e) {
        }
        try {
            if (TextUtils.equals("1", pro.getIntervalStatus())) {//是否区间价格 0 否 1 是
                tag_qujianjia.setVisibility(View.VISIBLE);
            } else {
                tag_qujianjia.setVisibility(View.GONE);
            }
        } catch (Exception e) {
        }
        try {
            if (TextUtils.equals("1", pro.getCustomizedStatus())) {//是否预订 0 否 1 是
                tag_yuding.setVisibility(View.VISIBLE);
            } else {
                tag_yuding.setVisibility(View.GONE);
            }
        } catch (Exception e) {
        }
        try {
            if (TextUtils.equals("1", pro.getGoodSalesModel())) {//销售模式（1：预售、2：现货)
                tag_yushou.setVisibility(View.VISIBLE);
            } else {
                tag_yushou.setVisibility(View.INVISIBLE);
            }
        } catch (Exception e) {
        }
    }
}
